package com.neusoft.yuejian12.yuejian_12.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.yuejian12.yuejian_12.R;
import com.neusoft.yuejian12.yuejian_12.activity.ProDetailActivity;
import com.neusoft.yuejian12.yuejian_12.javabean.ProBean;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.neusoft.yuejian12.yuejian_12.constant.Constant.PROFESSOR_PHOTO_URL;

/**
 * Created by ZTY on 2017/10/10.
 */

public class ProfessorListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List mDataList;
    private ViewHolder viewHolder;
    private LayoutInflater mLayoutInflaterp;
    public ProfessorListAdapter(Context mContext,List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflaterp = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v =mLayoutInflaterp.from(parent.getContext())
                .inflate(R.layout.cardview_professor, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ProBean entity = (ProBean) mDataList.get(position);
        if (null == entity)
            return;
        //绑定数据
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.proname.setText(entity.getPm_name());

        viewHolder.protype.setText(entity.getProfessor_type_name());
        String professor_imageBtn = PROFESSOR_PHOTO_URL+entity.getPm_pic();

        if (!professor_imageBtn.equals("")){
            Picasso.with(mContext).load(professor_imageBtn).error(R.drawable.ic_add).into(viewHolder.imagepro);
        }
        //点击item跳转
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putInt("pm_id",entity.getPm_id());
               // Log.d("o","pm_id");
                bundle.putInt("pc_id",entity.getPc_id());
             //   Log.d("o","pm_id");
                bundle.putString("pm_name",entity.getPm_name());
                bundle.putString("pm_info",entity.getPm_info());
                bundle.putString("pm_pic",entity.getPm_pic());
                bundle.putInt("professor_type_id",entity.getProfessor_type_id());
                bundle.putString("professor_type_name",entity.getProfessor_type_name());
                Intent intent=new Intent(mContext, ProDetailActivity.class);
                intent.putExtras(bundle);
                mContext.startActivity(intent);

            }
        });

    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView imagepro;
        TextView proname;
        TextView protype;
        public ViewHolder(View itemView) {
            super(itemView);
            proname = (TextView) itemView.findViewById(R.id.professor_name);
            imagepro = (ImageView) itemView.findViewById(R.id.professor_imageBtn);
            protype = (TextView) itemView.findViewById(R.id.professor_type);

        }
    }










}
